<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
//require_once("../vendor/qiniu/qiniu/rs.php");
require_once("../vendor/qiniu/php-sdk/qiniu/rsf.php");

Route::get('/', function()
{
	// return View::make('hello');
	$result = DB::select('select * from user', array());
	// var_dump($result);
	$username = Input::get('username');
	$password = Input::get('password');
	$name = Input::get('name');
	$nickname = Input::get('nickname');
	DB::insert('insert into user (ID, Username, Password, Name, NickName) values (?, ?, ?, ?, ?)', array(NULL, $username, $password, $name, $nickname));
	return Response::json($result);
});

Route::post('/', function()
{
	echo "post in root!";
});


Route::get('qiniu', function()
{
	$bucket = "yimark";
	$accessKey = "4cQTE8G4HxuAn8KF0vyPofCGlTgS7Mgovm_Z37SY";
	$secretKey = "ZHaQHyTn6ooELMgK0vrWxhV12kAVUKCKAE-P-0c7";
	Qiniu_SetKeys($accessKey, $secretKey);
	$client = new Qiniu_MacHttpClient(null);
	list($items, $marker,  $err) = Qiniu_RSF_ListPrefix($client, $bucket);
	echo "Qiniu_RS_List result: \n";
	if ($err !== null) {
		if ($err === Qiniu_RSF_EOF) {
    		//	var_dump($items);
		}
		else {
			var_dume($err);
		}
	} else {
    		//var_dump($items);
	}
	
	return Response::json($items);
});


Route::get('qiniu/{name}', function($name)
{
	$bucket = "yimark";
	$key=$name;//"YiMark2.ipa";
	$accessKey = "4cQTE8G4HxuAn8KF0vyPofCGlTgS7Mgovm_Z37SY";
	$secretKey = "ZHaQHyTn6ooELMgK0vrWxhV12kAVUKCKAE-P-0c7";
	Qiniu_SetKeys($accessKey, $secretKey);
	$client = new Qiniu_MacHttpClient(null);
	list($ret, $err) = Qiniu_RS_Stat($client, $bucket, $key);
	echo "Qiniu_RS_Stat result: \n";
	if ($err !== null) {
    		var_dump($err);
	} else {
    		var_dump($ret);
	}
});

Route::get('users', function()
{
	return Config::get('app.timezone');
	return View::make('users');
});
